<template>
	<view class="padding-30">
		<view class="bg-fff padding-30 border-radius20 margin-bottom30 flex-justAliCenter-column">
			<view class="flex-justAliCenter-column margin-bottom30">
				<view class="fontSize-15 color-000 margin-bottom20">我的余额(元)</view>
				<view class="fontSize-20 color-000 fontWeight-bold">{{userinfo.money?userinfo.money:0}}</view>
			</view>
			<view class="shenqing-btn flex-center" @click="$tools.navigateTo('/pages/mine/mine-list/apply-balance')">申请提现</view>
		</view>
		<view class="bg-fff border-radius20 margin-bottom30" style="padding: 30rpx 30rpx 0 30rpx;">
			<view class="fontSize-18 color-000 margin-bottom20 flex-center">余额明细</view>
			<view class="flex-between balance-item padding-bottom20 margin-bottom20" v-for="(item,index) in list" :key="index">
				<view>
					<view class="fontSize-13 color-000 margin-bottom20">{{item.memo}}</view>
					<view class="fontSize-13 color-999">{{item.createtime}}</view>
				</view>
				<view class="fontSize-15 color-000">{{item.money}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				userinfo:{},
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
			}
		},
		onLoad() {
			this.getUserInfo()
		},
		onShow() {
			if (uni.getStorageSync('token')) {
				this.page = 1
				this.limit = 10
				this.list = []
				this.getMoneyBill()
			}
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getMoneyBill().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getMoneyBill()
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			async getUserInfo(){
				let res = await this.$http.post(this.$api.user_info,{},{token:true})
				console.log(res)
				if(res.code == 1){
					this.userinfo = res.data
				}
			},
			// 获取积分明细列表
			async getMoneyBill(){
				let res = await this.$http.post(this.$api.money_bill,{page:this.page,limit:this.limit},{token:true})
				if (res.code == 1) {
					this.list = [...this.list, ...res.data]
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.balance-item:last-child{
		margin-bottom: 0;
		border-bottom: none;
	}
	.balance-item{
		margin-bottom: 20rpx;
		border-bottom: 1px solid #DBDBDB;
	}
	.shenqing-btn{
		width: 600rpx;
		height: 60rpx;
		padding: 10rpx 20rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #0BA062;
		background: #FFFFFF;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		border: 1rpx solid #0BA062;
	}
</style>